import java.util.Stack;

public class Test {
    class Solution {
        public int evalRPN(String[] tokens) {
            Stack<Integer> stack=new Stack<>();
            int num=0;
            for(int i=0;i<tokens.length;i++){
                if(tokens[i].equals("+")||tokens[i].equals("-")||tokens[i].equals("*")||tokens[i].equals("/")){
                    int num2= stack.pop();
                    int num1=stack.pop();

                    switch(tokens[i]){
                        case "+":
                            num=num1+num2;
                            break;
                        case "-":
                            num=num1-num2;

                            break;
                        case "*":
                            num=num1*num2;
                            break;
                        case "/":
                            num=num1/num2;
                            break;
                    }
                    stack.push(num);
                }else{
                    int l=Integer.valueOf(tokens[i]);
                    stack.push(l);
                }
            }
            if(stack.empty()) {
                return num;
            }
            return stack.pop();
        }
    }
    public static void main(String[] args) {

    }
}
